import { Body, Controller, Get, Param, Post, Query, Req } from '@nestjs/common';
import { Order_Service } from '../order/order.service';
import {
  Order_Find_Dto,
  Order_Cancel_Dto,
  Order_Pay_Dto,
  Order_Create_Dto,
} from '../order/assets/order.dto';
import { ApiTags } from '@nestjs/swagger';
import { IRequest } from '@/common/typeScripts/index';
import { util_ApiResponse_Base } from '@/common/util/apiResponse';
import { util_Index_ReturnContent } from '@/common/util/index';

@Controller('/web/orderWeb')
@ApiTags('orderWeb 订单')
export class OrderWeb_Controller {
  constructor(private readonly order_Service: Order_Service) {}

  @Get('/list')
  @util_ApiResponse_Base({
    dataType: 'dataType_list',
    //apiKey: '/web/orderWeb/list Get',
  })
  async orderWeb_FindByPage(@Query() query: Order_Find_Dto, @Req() req: IRequest) {
    return util_Index_ReturnContent(
      await this.order_Service.order_Web_FindByPageWeb({ ...query, userClientId: req.user.userId }),
    );
  }

  @Get('/detail/:id')
  @util_ApiResponse_Base({
    dataType: 'dataType_ell',
    //apiKey: '/web/orderWeb/detail/:id Get',
  })
  async orderWeb_FindOneById(@Param('id') id: number) {
    return util_Index_ReturnContent(await this.order_Service.order_Web_FindOneById(id));
  }

  @Post('/add')
  @util_ApiResponse_Base({
    dataType: 'dataType_add',
    //apiKey: '/web/orderWeb/add Post',
  })
  async orderWeb_Create(@Body() body: Order_Create_Dto, @Req() req: IRequest) {
    return util_Index_ReturnContent(await this.order_Service.order_Create(body, req));
  }

  @Post('/cancel/:id')
  @util_ApiResponse_Base({
    dataType: 'dataType_string',
    status: 201,
    description: '取消订单',
    //apiKey: '/web/orderWeb/cancel/:id Post',
    type: '取消订单成功',
    summary: '取消订单',
  })
  async orderWeb_Cancel(@Param() body: Order_Cancel_Dto, @Req() req: IRequest) {
    return util_Index_ReturnContent(await this.order_Service.order_Cancel(body, req));
  }

  @Post('/pay')
  @util_ApiResponse_Base({
    dataType: 'dataType_string',
    status: 201,
    description:
      '支付前置处理 修改订单支付类型，并根据支付类型处理支付请求，如果支付类型为支付宝，将返回支付表单。',
    //apiKey: '/web/orderWeb/pay Post',
    type: '若支付宝 返回支付表单',
    summary: '支付前置处理 根据支付类型处理支付请求',
  })
  async orderWeb_Pay(@Body() body: Order_Pay_Dto) {
    return await util_Index_ReturnContent(await this.order_Service.orderWeb_Pay(body));
  }

  @Post('/payCallBack')
  @util_ApiResponse_Base({
    dataType: 'dataType_string',
    type: 'success',
    summary: '支付成功回调',
  })
  async orderWeb_PayCallBack(@Body() body: any) {
    return util_Index_ReturnContent(await this.order_Service.orderWeb_PayCallBack(body));
  }
}
